package com.invengo.module_check.ui.fragment.widget.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.invengo.module_check.R;

import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;

public class ShelfAdapter<T> extends BindingRecyclerViewAdapter<T> {
    private int selectPosition = 0;

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }

    public int getSelectPosition() {
        return selectPosition;
    }

    @NonNull
    @Override
    public ViewDataBinding onCreateBinding(@NonNull LayoutInflater inflater, int layoutId, @NonNull ViewGroup viewGroup) {
        return super.onCreateBinding(inflater, layoutId, viewGroup);
    }

    @Override
    public void onBindBinding(@NonNull ViewDataBinding binding, int variableId, int layoutRes, int position, T item) {
        super.onBindBinding(binding, variableId, layoutRes, position, item);
        LinearLayout viewById = binding.getRoot().findViewById(R.id.dialogShelfLayout);
        if (viewById != null) {
            viewById.setBackgroundResource(position == selectPosition ? R.drawable.dialog_shelf_check : R.drawable.dialog_shelf_uncheck);
        }
    }
}
